close all
%% Section 1
% YOU WILL HAVE TWO CHOICES, IF YOU ARE CONTINUING TO PLOT ALREADY LOADED DATA
% THESE VARIABLES WON'T MATTER (CHOICE 2): 

% IF YOU LOAD NEW DATA (CHOICE 1) THEN:
% Specify name of RevPet .mat file:
% NOTE THAT THESE CAN BE CHANGED IN THE PROMPTS TOO
SavedOptimizedRun= 'RevPet_SSS_Siqueros_NEW_Mg6976_ER22_2';



%%% Name of plotting filenames. 
default1 = 'CCC_RevPet_Figs1_SameStep1';
default2 = 'CCC_RevPet_Figs2_Pressure';
default3 = 'CCC_RevPet_Figs3_Compare';
default4 = 'CCC_RevPet_Figs4_Latitude';
default5 = 'CCC_RevPet_SpecialFig11C_PRIMELT_Comparison';
%% Section 2 Prompted inputs below
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

promptreponse = input(sprintf('Do you want to: \n [1] Load a .mat file \n [2] Plot already loaded data? \n 1 or 2 [1]:'));
if promptreponse==1
    fprintf('<strong>Okay! Will load data \n </strong>')
    clearvars -except SavedOptimizedRun default1 default2 default3 default4 default5
    
    
    
    promptreponse = input(sprintf('Is ''%s'' the right RevPet .mat file to load for plotting? \n Y/N [Y]:',SavedOptimizedRun),'s');
    if strcmp(promptreponse,'Y')
        fprintf('<strong>Okay! Will use the default ''%s'' </strong>\n',SavedOptimizedRun)
    else
        SavedOptimizedRun = input('Okay, what should it be?:','s');
        fprintf('<strong>Okay! Will load ''%s'' instead </strong>\n',SavedOptimizedRun)
    end
    
    
    addpath(genpath(pwd));
    % Loads datasets, don't worry about changing
    load('WHDMM_1350')
    load('Galeetal2013_SuppTables')
    load('PUM') % Loads trace element source, if you want to change it, change it here!
    ColorsHERE
    load(SavedOptimizedRun)
    
    
    
    
    
    
    % Specify the maximum error you want points to plot:
    % All other erupted basalts with higher errors are plotted as small
    % symbols
    GoodDataError= 0.015; %default!
    promptreponse = input(sprintf('Is %g%% a good threshold OPLAM RMSD error for plotting? \n Y/N [Y]:',100.*GoodDataError),'s');
    if strcmp(promptreponse,'Y')
        fprintf('<strong>Okay! Will use the default %g%% </strong>\n',100.*GoodDataError)
    else
        GoodDataError = input('Okay, what should it be (enter # in percent)? e.g., [3]:');
        GoodDataError=GoodDataError./100;
        fprintf('<strong>Okay! Will change to %g%% </strong>\n',100.*GoodDataError)
    end
    
    maxPressure4Figures = 30;

    promptreponse = input(sprintf('Is %g kbars a good max pressure for plotting? \n Y/N [Y]:',maxPressure4Figures),'s');
    if strcmp(promptreponse,'Y')
        fprintf('<strong>Okay! Will use the default %g kbars </strong>\n',maxPressure4Figures)
    else
        maxPressure4Figures = input('Okay, what should it be in kbars)? e.g., [60]:');
        fprintf('<strong>Okay! Will change to %g kbars </strong>\n',maxPressure4Figures)
    end
    % Specify maximum pressure for figures with pressure axes
    

    highlight_ReverseFC = find(OPALM_RMSD <= GoodDataError)';
    BAD_ReverseFC = find(OPALM_RMSD > GoodDataError)';
    BAD_ReverseFC_nan = find(isnan(OPALM_RMSD));
    BAD_ReverseFC=sort([BAD_ReverseFC'; BAD_ReverseFC_nan]);
    BAD_ReverseFC_labels = CombinedLabel(BAD_ReverseFC);
    
    [Unique_BAD_labels,Unique_BAD_labels_Rows] = unique(BAD_ReverseFC_labels,'stable');
    Unique_BAD_labels_leg= strcat('NoGoodSoln-', Unique_BAD_labels(:))';
    UniqueLabels_leg= strcat('Input-', UniqueLabels(:))';
    % But do change the primary melt symbol markers, colors, and sizes if you like:
    UniqueLabels_Primary= strcat('RevPetPrimary-', UniqueLabels(:))';
    runningColors_LINE_Primary = runningColors_LINE;
    runningColors_FILL_Primary = runningColors_FILL;
    
    
    
    PrimarySymbol = 'v';
    
    promptreponse = input(sprintf('Is ''%s'' a good symbol to plot corrected primary melt compositions?\n Y/N [Y]:',PrimarySymbol),'s');
    if strcmp(promptreponse,'Y')
        fprintf('<strong>Okay! Will use the default ''%s'' </strong>\n',PrimarySymbol)
    else
        PrimarySymbol = input('Okay, what should it be, no quotes? e.g., [s]: ','s');
        fprintf('<strong>Okay! Will change to ''%s'' </strong>\n',PrimarySymbol)
    end
    runningMarkersPrimary = cell(size(runningMarkers));
    runningMarkersPrimary(:)={PrimarySymbol}; % Here I've changed the symbols to be triangles
    
    
    SizesPrimary=13;
    
    promptreponse = input(sprintf('Is %g a good size to plot corrected primary melt compositions?\n Y/N [Y]:',SizesPrimary),'s');
    if strcmp(promptreponse,'Y')
        fprintf('<strong>Okay! Will use the default %g </strong>\n',SizesPrimary)
    else
        SizesPrimary = input('Okay, what should it be? e.g., [20]:');
        fprintf('<strong>Okay! Will change to %g </strong>\n',SizesPrimary)
    end
    
    runningSizesPrimary = cell(size(runningMarkers));
    runningSizesPrimary(:)={num2str(SizesPrimary)};% Here I've changed their size to 13
    
    
    
    badSize = 7;
    
    promptreponse = input(sprintf('Is %g a good size to plot data that failed \n or has high OPLAM RMSD error?\n Y/N [Y]:',badSize),'s');
    if strcmp(promptreponse,'Y')
        fprintf('<strong>Okay! Will use the default %g </strong>\n',badSize)
    else
        badSize = input('Okay, what should it be? e.g., [20]:');
        fprintf('<strong>Okay! Will change to %g </strong>\n',badSize)
    end
    runningSizesBad = {num2str(badSize)};
    
    
    % This section is if you want to compare to a different Step1 set of
    % basalts that you did not neccessary run through RevPet
    % load('SSS_Gale2014_Niu2008_Perfit1996GaleEPR_Niu2008PRIMELT_PATHS_PRIMELT3')
    % %load('SSS_Gale2014_Niu2008_Hays2004Perfit1996_GaleEPRNiu2008_PRIMELT_PATHSPRIMELT3_')
    % MajorData_Step1= runningMajors;
    % ColorsLine_Step1= runningColors_LINE;
    % ColorsFill_Step1= runningColors_FILL;
    % Sizes_Step1= runningSizes;
    % Markers_Step1= runningMarkers;
    % [UniqueLabels,UniqueLabels_Rows] = unique(runningLabels,'stable');%unique(runningLabels,'stable');
    % UniqueLabels_Rows_step1 = UniqueLabels_Rows;
    % runningLabels_step1 = runningLabels;
    
    
    removeLeg=[];
    aaas=1;
    for zz = UniqueLabels_Rows'
        i =find(ismember(CombinedLabel, CombinedLabel(zz)));
        
        p=ismember(i,highlight_ReverseFC);
        i(p==0)=[];
        
        if isempty(i)==1
            removeLeg=[removeLeg, aaas];
        end
        
        aaas=aaas+1;
    end
    
    %UniqueLabels_EruptedGood
    UniqueLabels_AllBad = UniqueLabels(removeLeg);
    UniqueLabels(removeLeg)=[];
    
    UniqueLabels_leg(removeLeg)=[];
    UniqueLabels_Primary(removeLeg)=[];
    
    
    %%% NEEDED FOR NOW
    RevPetResultsTable_ResultsOnly = RevPetResultsTable;
    RevPetResultsTable_ResultsOnly.OPALM_RMSD = str2double(cellfun(@(x) regexprep(x,'%',''),cellstr(RevPetResultsTable_ResultsOnly.OPALM_RMSD),'uni',0));
    
    
    
    RevPetResultsTable_ResultsOnly.totalFC = str2double(cellfun(@(x) regexprep(x,'%',''),cellstr(RevPetResultsTable_ResultsOnly.totalFC),'uni',0));
    %RevPetResultsTable_ResultsOnly.totalFC = cellfun(@(x) str2num(x),RevPetResultsTable_ResultsOnly.totalFC,'uni',0);
    
    RevPetResultsTable_ResultsOnly.OPA_FC = str2double(cellfun(@(x) regexprep(x,'%',''),cellstr(RevPetResultsTable_ResultsOnly.OPA_FC),'uni',0));
    %RevPetResultsTable_ResultsOnly.OPA_FC = cellfun(@(x) str2num(x),RevPetResultsTable_ResultsOnly.OPA_FC,'uni',0);
    
    RevPetResultsTable_ResultsOnly.OP_FC = str2double(cellfun(@(x) regexprep(x,'%',''),cellstr(RevPetResultsTable_ResultsOnly.OP_FC),'uni',0));
    %RevPetResultsTable_ResultsOnly.OP_FC = cellfun(@(x) str2num(x),RevPetResultsTable_ResultsOnly.OP_FC,'uni',0);
    
    RevPetResultsTable_ResultsOnly.O_FC = str2double(cellfun(@(x) regexprep(x,'%',''),cellstr(RevPetResultsTable_ResultsOnly.O_FC),'uni',0));
    %RevPetResultsTable_ResultsOnly.O_FC = cellfun(@(x) str2num(x),RevPetResultsTable_ResultsOnly.O_FC,'uni',0);
    
    RevPetResultsTable_ResultsOnly.OPAM_RMSD_Erupted = str2double(cellfun(@(x) regexprep(x,'%',''),cellstr(RevPetResultsTable_ResultsOnly.OPAM_RMSD_Erupted),'uni',0));
    %RevPetResultsTable_ResultsOnly.OPAM_RMSD_Erupted = cellfun(@(x) str2num(x),RevPetResultsTable_ResultsOnly.OPAM_RMSD_Erupted,'uni',0);
    
    RevPetResultsTable_ResultsOnly.OPM_RMSD_Erupted = str2double(cellfun(@(x) regexprep(x,'%',''),cellstr(RevPetResultsTable_ResultsOnly.OPM_RMSD_Erupted),'uni',0));
    %RevPetResultsTable_ResultsOnly.OPM_RMSD_Erupted = cellfun(@(x) str2num(x),RevPetResultsTable_ResultsOnly.OPM_RMSD_Erupted,'uni',0);
    
    
else if promptreponse==2
        fprintf('<strong>Okay! Will not clear any data </strong>\n')
    end
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



promptreponse123 = input('Do you want to make plots that are:\n[1] the same as in ImportPlot but with reverse fractionation paths and primary melts \n[2] show RevPet errors and temperature-pressures of melting? \n[3] compare to other estimates of melting temperatures and pressures? \n[4] compare to Lat and Long \n[5] Other? \n 1,2,3,4, or 5 [1]:');

if promptreponse123==1
    
    promptreponse = input(sprintf('Is ''%s'' the right file, or did you change the name? \n Y/N [Y]:',default1),'s');
    if strcmp(promptreponse,'Y')
        fprintf('<strong>Okay! Will execute ''%s'' </strong>\n',default1)
    else
        default1 = input('Okay, what should the name be)?:');
        fprintf('<strong>Okay, changed! Will execute ''s'' </strong>\n',default1)
    end
    eval(default1)
    
else if promptreponse123==2
        promptreponse = input(sprintf('Is ''%s'' the right file, or did you change the name? \n Y/N [Y]:',default2),'s');
        if strcmp(promptreponse,'Y')
            fprintf('<strong>Okay! Will execute ''%s'' </strong>\n',default2)
        else
            default2 = input('Okay, what should the name be)?:');
            fprintf('<strong>Okay, changed! Will execute ''s'' </strong>\n',default2)
        end
        eval(default2)
        
        
    else if promptreponse123==3
            promptreponse = input(sprintf('Is ''%s'' the right file, or did you change the name? \n Y/N [Y]:',default3),'s');
            if strcmp(promptreponse,'Y')
                fprintf('<strong>Okay! Will execute ''%s'' </strong>\n',default3)
            else
                default3 = input('Okay, what should the name be)?:');
                fprintf('<strong>Okay, changed! Will execute ''%s'' </strong>\n',default3)
            end
            eval(default3)
        else if promptreponse123==4
                promptreponse = input(sprintf('Is ''%s'' the right file, or did you change the name? \n Y/N [Y]:',default4),'s');
                if strcmp(promptreponse,'Y')
                    fprintf('<strong>Okay! Will execute ''%s'' </strong>\n',default4)
                else
                    default4 = input('Okay, what should the name be)?:');
                    fprintf('<strong>Okay, changed! Will execute ''s'' </strong>\n',default4)
                end
                eval(default4)
            else if promptreponse123==5
                    promptreponse = input(sprintf('Is ''%s'' the right file, or did you change the name? \n Y/N [Y]:',default5),'s');
                    if strcmp(promptreponse,'Y')
                        fprintf('<strong>Okay! Will execute ''%s'' </strong>\n',default5)
                    else
                        default5 = input('Okay, what should the name be)?:');
                        fprintf('<strong>Okay, changed! Will execute ''s'' </strong>\n',default5)
                    end
                    eval(default5)
                    
                end
            end
        end
    end
end
%%
disp('Finished Plotting')
disp('*Find, edit, and redraw figures in code by searching for figure number e.g., figure(4) in the right file')
disp('**In particular, you probably want to move the legends prior to saving!')
disp('***When ready to save figures, execute command ''SaveFigures''')


